<?php

require('header.php');
require('table_des_matieres.php');

if (isset($editMode))
{

	echo '		<fieldset>
					<legend>'.$language[$_SESSION['lang']]["Edit"].'</legend>
					
					<form method="POST">
						<table>
							<tr>
								<td><label for="titre_avis">'.$language[$_SESSION['lang']]["Title"].'</label></td>
								<td><input type="text" name="titre_avis" value="'.$titre_avis.'"></td>
							</tr>
							<tr>
								<td><label for="commentaire">'.$language[$_SESSION['lang']]["Com"].'</label></td>
								<td><textarea name="commentaire" rows="10" cols="100">'.str_replace("<br />","",$commentaire).'</textarea></td>
							</tr>
							<tr>
								<td><label for="notation">'.$language[$_SESSION['lang']]["Notation"].'</label></td>
								<td><select name="notation">';
								
	for ($i = 0; $i < 11; $i++)
	{
		if ($i != $note)
		{
			echo '<option value="'.$i.'">'.$i.'</option>';
		}
		else
		{
			echo '<option value="'.$i.'" SELECTED>'.$i.'</option>';
		}
	}							
								
	echo '						</select></td>
							</tr>
						</table>
						
					<input type="hidden" name="commentId" value="'.$_POST["commentId"].'">
					<input type="hidden" name="good" value="'.$_POST["good"].'">
					<input type="submit" name="validerEdit" value="'.$language[$_SESSION['lang']]["Valid"].'">
						
					</form>
					
				</fieldset>';
	
}
else
{

	foreach ($Locations as $Location)
	{
		echo '	<fieldset>
					<legend>'.$Location->bien->nom.'</legend>
				
					'.$language[$_SESSION['lang']]["HaveBeenLocatorOf"].' <a href="location.php?id='.$Location->bien->id_bien.'">'.$Location->bien->nom.'</a> '.$language[$_SESSION['lang']]["From"].' '.$Location->date_debut.' '.$language[$_SESSION['lang']]["For"].' '.$Location->duree.' '.$language[$_SESSION['lang']]["Days"].'.<br />
					<span class="locationLegend">'.$language[$_SESSION['lang']]["PriceOfLocation"].' :</span> '.$Location->prix.' €<br />
					<span class="locationLegend">'.$language[$_SESSION['lang']]["PriceAfterReduction"].' :</span> '.$Location->promo.' €<br /><br />
					
					<span class="locationLegend">'.$language[$_SESSION['lang']]["You"].' ';
					
					if (!empty($Location->commentaire))
					{
						echo $language[$_SESSION['lang']]["LeftComment"].' (';
						
						if ($Location->commentaire->authorized)
						{
							echo $language[$_SESSION['lang']]["Authorized"];
						}
						else
						{
							echo $language[$_SESSION['lang']]["Unauthorized"];
						}
						
						echo ') : </span>';
						echo '	<fieldset style="clear:both;">
								<legend>'.$Location->commentaire->titre_avis.'</legend>
								<div style="width:100%;">'.$Location->commentaire->commentaire.'</div>
								<div style="float:right; text-align:right;"><img title="'.$Location->commentaire->notation.'/10" src="CSS/Note/'.intval($Location->commentaire->notation).'.png"/><br />
									<span style="font-size:12px;">'.$language[$_SESSION['lang']]["posted"].' '.date("d M Y",$Location->commentaire->timestamp).'</span>
								</div>
							</fieldset>';
						echo '	<form method="POST" style="float:left">
									<input type="hidden" name="good" value="'.$Location->bien->id_bien.'">
									<input type="hidden" name="commentId" value="'.$Location->commentaire->id_avis.'">
									<input type="submit" name="editComment" value="'.$language[$_SESSION['lang']]["EditComment"].'">
								</form>';	
								
						echo '	<form method="POST" style="float:right">
									<input type="hidden" name="good" value="'.$Location->bien->id_bien.'">
									<input type="hidden" name="commentId" value="'.$Location->commentaire->id_avis.'">
									<input type="submit" name="deleteComment" value="'.$language[$_SESSION['lang']]["DeleteComment"].'">
								</form>';
								
						if (isset($_POST["Images"]))
						{
							echo '<form method="POST" enctype="multipart/form-data" style="float:left; clear:right">
									  <input type="file" name="file" /><br />
									  <input type="hidden" name="good" value="'.$Location->bien->id_bien.'"/>
									  <input type="submit" name="validerFile" value="'.$language[$_SESSION['lang']]["Valid"].'" >
									</form>';
						}
						else
						{	
							if (isset($extError))
							{
								echo '<fieldset style="float:left; clear:right;">'.$language[$_SESSION['lang']]["WrongExt"].'</fieldset><br /><br />';
							}
							elseif (isset($upload))
							{
								if ($upload)
								{
									echo '<fieldset style="float:left; clear:right;">'.$language[$_SESSION['lang']]["SuccessUpload"].'</fieldset><br /><br />';
								}
								else
								{
									echo '<fieldset style="float:left; clear:right;">'.$language[$_SESSION['lang']]["FailedUpload"].'</fieldset><br /><br />';
								}
							}
							
							echo '	<form method="POST" style="float:left; clear:both;">
										<input type="submit" name="Images" value="'.$language[$_SESSION['lang']]["AddPic"].'" />
									</form>';
						}	
						
							
					}
					else
					{
						echo $language[$_SESSION['lang']]["NoComment"].'.</span>';
						echo '	<form method="POST">
									<input type="hidden" name="good" value="'.$Location->bien->id_bien.'">
									<input type="hidden" name="commentId" value="0">
									<input type="submit" name="editComment" value="'.$language[$_SESSION['lang']]["AddComment"].'">
								</form>';
					}
					
		echo '	</fieldset>';
	}
	
}

require('footer.php');

?>
